#!/usr/bin/perl

use strict;
use warnings;
use FindBin;
use File::Spec;
use Getopt::Long;
use IO::File;
use Imager;

my $url = 'http://www.google.co.jp/';
my $scale = 1;

GetOptions ( "url=s"   => \$url,
             "scale=f"  => \$scale);

my $capture_command = File::Spec->catfile($FindBin::Bin, 'safaricapture.app');
my $capture_image = File::Spec->catfile($FindBin::Bin, 'site.png');
my $crop_image = File::Spec->catfile($FindBin::Bin, 'site-'.time.'.png');
my $url_file = File::Spec->catfile($FindBin::Bin, 'url.txt');

my $fh = IO::File->new;
if( $fh->open("> $url_file") ){
    print $fh $url;
    $fh->close;
}

system `$capture_command`;


my $image = Imager->new;
$image->read(file => $capture_image);

my $newimage = $image->crop(left=>0, top=>100, width=>1024,height=>768);
my $i = $newimage->scale(scalefactor => $scale);
$i->write(file => $crop_image);


__END__
